package com.lmscn.lms.api.model;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

/**
 * 资讯点赞关系表
 * 
 * @author zhang.xx
 * @date 2016年11月30日11:20:12
 * 
 */
public class ArticleStudentStatus extends Model<ArticleStudentStatus> {

	public static final ArticleStudentStatus dao = new ArticleStudentStatus();

	public void save(ArticleStudentStatus articleStudentStatus, Long articleId, Long studentId, String type) {
		articleStudentStatus.set("article_id", articleId);
		articleStudentStatus.set("student_id", studentId);
		articleStudentStatus.set("target_type", type);
		articleStudentStatus.remove("id").save();
	}

	public ArticleStudentStatus getArticleStudentStatus(Long articleId, Long studentId, String type) {
		return dao.findFirst("select * from t_article_student_status "
				+ "where article_id =? and student_id = ? and target_type = ?", articleId, studentId, type);
	}

	/**
	 * 分页查询资讯收藏
	 * 
	 * @date 2016年12月21日15:10:21
	 * @param pageNumber
	 * @param pageSize
	 * @param sql
	 * @param paras
	 * @return
	 */
	public Page<ArticleStudentStatus> getArticleCollectionPage(int pageNumber, int pageSize, String sql, Object[] paras) {
		return dao.paginate(pageNumber, pageSize, "select t.* ", sql, paras);
	}

	/**
	 * 删除资讯的收藏，点赞等类型记录
	 * 
	 * @param studentId
	 * @param courseId
	 * @param type
	 * @return
	 */
	public int deleteMyCollection(Long studentId, Long articleId, String type) {
		return Db.update("delete from t_article_student_status " + "where article_id =? and student_id = ? and target_type = ?",
				articleId, studentId, type);
	}

}
